package com.yxwl.demo.ui.print;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.widget.NestedScrollView;

import com.print.base.bean.TaskCallBean;
import com.print.base.listen.ConnectListener;
import com.print.base.listen.TaskCallback;
import com.print.printer.Command;
import com.yxwl.demo.R;
import com.yxwl.demo.ui.base.BaseActivity;
import com.yxwl.demo.ui.print.printer.PrinterUtil;
import com.yxwl.demo.utils.StringUtil;
import com.yxwl.demo.widget.CustomProgress;
import com.yxwl.demo.widget.LogView;
import com.yxwl.demo.widget.MenuView;

import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class PrintActivity extends BaseActivity {

    private ImageView ic;
    protected LogView logView;
    public MenuView menuContent;
    public static WeakReference<ImageView> icWR;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_print;
    }

    @Override
    protected void initView() {
        logView = findViewById(R.id.log_content);
        menuContent = findViewById(R.id.menu_content);
        ic = findViewById(R.id.connect_ic);
        icWR = new WeakReference<>(ic);
    }

    @Override
    protected void initData() {
        setTitle();
        initPrinter();
    }
    protected void setTitle() {
        TextView titleTv = findViewById(R.id.title);
        titleTv.setText(PrinterUtil.getInstance().getItem().name);
    }

    @Override
    protected void initListen() {
        findViewById(R.id.menu).setOnClickListener(getOnClickListen());
        findViewById(R.id.print_img).setOnClickListener(getOnClickListen());
        findViewById(R.id.back).setOnClickListener(getOnClickListen());

    }

    @Override
    protected void widgetClick(View view, int id) {
        if (id == R.id.back) {
            finish();
        } else if (id == R.id.menu) {
            menuContent.setVisibility(menuContent.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
        } else if (id == R.id.print_img) {
            PrinterUtil.getInstance().print(PrintActivity.this);
        }
    }


    @Override
    protected void onDestroy() {
        PrinterUtil.getInstance().release();
        super.onDestroy();
    }

    public void initPrinter() {
        menuContent.init();
        logView.init();
        menuContent.connect();
    }


}